﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.ServiceModel;
namespace WP7TransferDataTool
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.lblDefaultFolder.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            this.lblServerName.Text = System.Net.Dns.GetHostName();
        }

        private void btnStartService_Click(object sender, EventArgs e)
        {
            if (ServiceHostCtrl.ServiceState == CommunicationState.Closed)
            {
                FolderBrowserDialog folderDialog = new FolderBrowserDialog();
                folderDialog.SelectedPath = this.lblDefaultFolder.Text;


                DialogResult dialogResult = folderDialog.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    this.lblDefaultFolder.Text = folderDialog.SelectedPath;
                }
                else
                {
                    return;
                }

                TransferDataService.DefaultFolder = this.lblDefaultFolder.Text;

                btnStartService.Text = "Stop Service";
                btnStartService.Enabled = false;
                ServiceHostCtrl.StartService(this.lblServerName.Text);
                btnStartService.Enabled = true;
                return; 
            }
            
            if (ServiceHostCtrl.ServiceState == CommunicationState.Opened)
            {
                btnStartService.Text = "Start Service";
                btnStartService.Enabled = false;
                ServiceHostCtrl.StopService();
                btnStartService.Enabled = true;
                return;
            }
        }

      
    }
}
